﻿using NfsBLL;
using NfsCommon.Util;
using NfsModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MobileWeb.Controllers
{
    public class CertificateController : Controller
    {
        public ActionResult Index()
        {

            int id = int.Parse(CookieHelper.GetDecodeCookie("nfs_UserId"));
            AgencyBLL bll = new AgencyBLL();
            agency model = bll.GetModel_account(id);
            if (model.state != 1)
            {
                ViewData["count"] = "0";
                ViewData["img"] = "";
            }
            else
            {
                ViewData["img"] = model.sq_img;
                ViewData["count"] = "1";
            }
            return View();
        }
        /// <summary>
        /// 查看下级经销商的证书
        /// </summary>
        /// <returns></returns>
        public ActionResult ShareImg()
        {
            int id = int.Parse(CookieHelper.GetDecodeCookie("nfs_UserId"));
            int agency_id = Request["agency_id"] != "" ? int.Parse(Request["agency_id"]) : 0;
            AgencyBLL bll = new AgencyBLL();
            agency model = bll.GetModel(agency_id);
            if (model.state != 1)
            {
                ViewData["count"] = "0";
                ViewData["img"] = "";
            }
            else
            {
                ViewData["img"] = model.sq_img;
                ViewData["count"] = "1";
            }
            return View();
        }
        #region 获取当前登录人的经销商信息
        public JsonResult Get_IndexInfo()
        {
            try
            {
                int id = int.Parse(CookieHelper.GetDecodeCookie("nfs_UserId"));
                AgencyBLL bll = new AgencyBLL();
                agency model = bll.GetModel_account(id);
                if (model.state != 1)
                {
                    return Json(new { MessageCode = "100"}, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { MessageCode = "0", img = model.sq_img }, JsonRequestBehavior.AllowGet);//未被授权
                }
            }
            catch (Exception)
            {

                return Json(new { MessageCode = "200" }, JsonRequestBehavior.AllowGet);

            }

        }
    #endregion
        #region 获取下级经销商信息
        public JsonResult query_parAgList()
        {
            try
            {
                int id = int.Parse(CookieHelper.GetDecodeCookie("nfs_UserId"));
                AgencyBLL bll = new AgencyBLL();
                agency model = bll.GetModel_account(id);
                List<agency> list = bll.GetModelList(" valid=1 and shState=1 and parents_id=" + model.id + "");
                return Json(new { MessageCode = "0", PagencyList = list }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {

                return Json(new { MessageCode = "200" }, JsonRequestBehavior.AllowGet);

            }

        }
        #endregion
    }
}
